package com.kfm.base.thread.day01;

import java.util.concurrent.atomic.AtomicInteger;

public class Demo02 {

    public static void main(String[] args) {
        // 任务对象
        MyRunnable myRunnable = new MyRunnable();
        // 创建线程对象
        Thread t1 = new Thread(myRunnable, "线程1：");
        Thread t2 = new Thread(myRunnable, "线程2：");

        Runnable r = new Runnable() {
            @Override
            public void run() {
                String name = Thread.currentThread().getName();
                for (int i = 0; i < 10; i++) {
                    System.out.println(name + " : " + i);
                }
            }
        };

        Runnable runnable = () -> {
            String name = Thread.currentThread().getName();
            for (int i = 0; i < 10; i++) {
                System.out.println(name + " : " + i);
            }
        };

        Thread thread = new Thread(runnable);
        Thread thread1 = new Thread(runnable);

        int num = 0;
        AtomicInteger atomicInteger = new AtomicInteger();
        Runnable r1 = new Runnable() {
            @Override
            public void run() {
                String name = Thread.currentThread().getName();
                for (int i = 0; i < 10; i++) {
                    System.out.println(name + " : " + i);
                }
            }
        };


        Runnable r2 = () -> {
            String name = Thread.currentThread().getName();
            for (int i = 0; i < 10; i++) {
                System.out.println(name + " : " + i);
            }
        };

        // 启动线程
        t1.start();
        t2.start();


    }
}


// 线程执行任务
class MyRunnable implements Runnable {

    int count = 0;

    @Override
    public void run() {
        for (int i = 0; i < 10; i++) {
            String name = Thread.currentThread().getName();
            System.out.println(name + ": " + i);
        }
    }
}
